package com.example.chatchatbackend.Controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.chatchatbackend.entity.RestBean;
import com.example.chatchatbackend.entity.dto.Payment;

import com.example.chatchatbackend.entity.vo.request.PaymentVO;

import com.example.chatchatbackend.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 丁真
 * @since 2024-10-28 05:03:47
 */
@Slf4j
@RestController
@RequestMapping("/api/payment")
public class PaymentController {
    @Autowired
    private PaymentService paymentService;

    @GetMapping
    public RestBean<List<Payment>> getAll(){
        List<Payment> paymentList = paymentService.getAllPayment();
        return RestBean.success(paymentList);
    }

    @PostMapping
    public RestBean<PaymentVO> insertAdv(@RequestBody PaymentVO paymentListVO){
        PaymentVO insertPaymentVO = paymentService.insertPayment(paymentListVO);
        return RestBean.success(insertPaymentVO);

    }

    @PostMapping("/list")
    public RestBean<List<PaymentVO>> insertAdvList (@RequestBody List<PaymentVO> paymentListVO){
        List<PaymentVO> PaymentList = paymentService.insertPaymentList(paymentListVO);
        return RestBean.success(PaymentList);
    }

    @GetMapping("/pageThree")
    public RestBean<IPage<Payment>> pageThree(@RequestParam(value = "pageNum" ,defaultValue = "1") Integer pageNum,
                                               @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize){
        return RestBean.success(paymentService.pageThree(pageNum, pageSize));
    }

    @PutMapping
    public RestBean<PaymentVO> updatePayment(@RequestBody PaymentVO paymentVO){
        return RestBean.success(paymentService.updatePayment(paymentVO));

    }

    @DeleteMapping("/ids")
    public RestBean<String> delete(@RequestBody List<Integer> ids) {
        paymentService.deleteByIds(ids);
        return RestBean.success("删除成功");
    }
}
